<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ZooKeeper 如何处理脑裂现象</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        /* 首字下沉效果 */
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.5rem;
            font-weight: 700;
            color: #4a5568;
            font-family: 'Noto Serif SC', serif;
        }
        
        /* 卡片悬停效果 */
        .card-hover {
            transition: all 0.3s ease;
            cursor: pointer;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        /* 渐变文字效果 */
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        /* 章节标题装饰 */
        .section-title::before {
            content: '';
            position: absolute;
            left: -30px;
            top: 50%;
            transform: translateY(-50%);
            width: 5px;
            height: 30px;
            background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
            border-radius: 3px;
        }
        
        /* 引用样式 */
        .quote-box {
            position: relative;
            padding-left: 3rem;
        }
        
        .quote-box::before {
            content: '"';
            position: absolute;
            left: 0;
            top: -10px;
            font-size: 4rem;
            color: #e2e8f0;
            font-family: 'Noto Serif SC', serif;
        }
        
        /* 数字标记样式 */
        .number-badge {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 2rem;
            height: 2rem;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 50%;
            font-weight: 700;
            margin-right: 0.5rem;
        }
        
        /* 平滑滚动 */
        html {
            scroll-behavior: smooth;
        }
        
        /* Mermaid 图表样式 */
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero 区域 -->
    <section class="relative overflow-hidden bg-gradient-to-br from-purple-900 via-indigo-800 to-blue-700 text-white">
        <div class="absolute inset-0 bg-black opacity-20"></div>
        <div class="relative container mx-auto px-6 py-24 text-center">
            <h1 class="text-5xl md:text-7xl font-bold mb-6 animate-pulse">
                ZooKeeper 如何处理
                <span class="block mt-2 gradient-text bg-gradient-to-r from-yellow-300 to-pink-300">脑裂现象</span>
            </h1>
            <p class="text-xl md:text-2xl mb-8 text-gray-200 max-w-3xl mx-auto">
                深入探索分布式系统中的一致性保障机制
            </p>
            <div class="flex justify-center space-x-4">
                <div class="bg-white bg-opacity-20 backdrop-blur-lg rounded-lg px-6 py-3">
                    <i class="fas fa-network-wired mr-2"></i>
                    分布式协调
                </div>
                <div class="bg-white bg-opacity-20 backdrop-blur-lg rounded-lg px-6 py-3">
                    <i class="fas fa-shield-alt mr-2"></i>
                    高可用性
                </div>
                <div class="bg-white bg-opacity-20 backdrop-blur-lg rounded-lg px-6 py-3">
                    <i class="fas fa-sync-alt mr-2"></i>
                    一致性保证
                </div>
            </div>
        </div>
        <div class="absolute bottom-0 left-0 right-0">
            <svg viewBox="0 0 1440 120" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M0 120L60 105C120 90 240 60 360 45C480 30 600 30 720 37.5C840 45 960 60 1080 67.5C1200 75 1320 75 1380 75L1440 75V120H1380C1320 120 1200 120 1080 120C960 120 840 120 720 120C600 120 480 120 360 120C240 120 120 120 60 120H0Z" fill="#f5f7fa"/>
            </svg>
        </div>
    </section>

    <!-- 主要内容区域 -->
    <main class="container mx-auto px-6 py-12 max-w-6xl">
        
        <!-- 引言部分 -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <div class="prose prose-lg max-w-none">
                <p class="drop-cap text-gray-700 leading-relaxed text-lg">
                    在分布式系统中，"脑裂"现象是一种普遍而复杂的问题，指的是在网络分区或节点故障的情况下，系统中的多个节点可能各自认为自己是主节点，从而导致数据的不一致性和操作的冲突。这种情况不仅会影响系统的可用性，还可能对数据的完整性造成严重威胁。
                </p>
                <div class="mt-6 p-6 bg-gradient-to-r from-purple-50 to-indigo-50 rounded-xl">
                    <p class="text-gray-700 mb-0">
                        ZooKeeper 是一个广泛应用于分布式系统中的工具，负责提供配置管理、命名、同步服务以及集群管理。为了确保系统的一致性，ZooKeeper 采用了一系列精巧的设计策略，包括选举机制、心跳监控和事务日志等。
                    </p>
                </div>
            </div>
        </section>

        <!-- 脑裂现象概述 -->
        <section class="mb-12">
            <h2 class="text-4xl font-bold mb-8 relative section-title pl-8 text-gray-800">
                <i class="fas fa-brain mr-3 text-purple-600"></i>脑裂现象概述
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                        <span class="number-badge">1</span>脑裂现象的成因
                    </h3>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <i class="fas fa-network-wired text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold text-gray-700">网络分区</h4>
                                <p class="text-gray-600">在分布式系统中，网络故障或节点故障可能会导致部分节点与其他节点失去联系。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-server text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold text-gray-700">节点故障</h4>
                                <p class="text-gray-600">如果一个节点突然失效或重启，它可能在恢复后误认为自己仍然是主节点。</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                        <span class="number-badge">2</span>脑裂现象的影响
                    </h3>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <i class="fas fa-exclamation-triangle text-red-600 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold text-gray-700">数据不一致性</h4>
                                <p class="text-gray-600">多个节点独立进行写操作会导致数据的不一致。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-times-circle text-red-600 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold text-gray-700">系统可用性降低</h4>
                                <p class="text-gray-600">由于存在多个主节点，系统可能会在决策上陷入困境。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 应对策略 -->
            <div class="mt-8 bg-gradient-to-r from-indigo-50 to-purple-50 rounded-xl p-8">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">
                    <i class="fas fa-shield-alt mr-2 text-indigo-600"></i>应对脑裂现象的策略
                </h3>
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="bg-white rounded-lg p-6 shadow-md">
                        <i class="fas fa-vote-yea text-3xl text-indigo-600 mb-3"></i>
                        <h4 class="font-semibold mb-2">主从节点选举机制</h4>
                        <p class="text-sm text-gray-600">使用选举算法确保在任意时间只有一个主节点存在。</p>
                    </div>
                    <div class="bg-white rounded-lg p-6 shadow-md">
                        <i class="fas fa-heartbeat text-3xl text-indigo-600 mb-3"></i>
                        <h4 class="font-semibold mb-2">健康监测和故障检测</h4>
                        <p class="text-sm text-gray-600">引入心跳机制来定期检查节点的健康状态。</p>
                    </div>
                    <div class="bg-white rounded-lg p-6 shadow-md">
                        <i class="fas fa-handshake text-3xl text-indigo-600 mb-3"></i>
                        <h4 class="font-semibold mb-2">一致性协议</h4>
                        <p class="text-sm text-gray-600">实施分布式一致性协议，保证系统的稳定运行。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- ZooKeeper 设计目标 -->
        <section class="mb-12">
            <h2 class="text-4xl font-bold mb-8 relative section-title pl-8 text-gray-800">
                <i class="fas fa-bullseye mr-3 text-purple-600"></i>ZooKeeper 的设计目标
            </h2>
            
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <div class="quote-box mb-6">
                    <p class="text-lg text-gray-700 italic">
                        ZooKeeper 是一个开源的分布式协调服务，主要用于在分布式系统中提供一致性、可靠性和可扩展性。其设计目标旨在解决分布式系统中常见的协调和同步问题。
                    </p>
                </div>
                
                <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6 mt-8">
                    <div class="bg-gradient-to-br from-purple-100 to-indigo-100 rounded-lg p-6">
                        <i class="fas fa-cloud text-3xl text-purple-700 mb-3"></i>
                        <h3 class="text-xl font-semibold mb-2">高可用性</h3>
                        <p class="text-gray-700">通过冗余机制和快速故障恢复，确保服务的连续性。</p>
                    </div>
                    <div class="bg-gradient-to-br from-blue-100 to-cyan-100 rounded-lg p-6">
                        <i class="fas fa-check-double text-3xl text-blue-700 mb-3"></i>
                        <h3 class="text-xl font-